﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DreamBuilder.Common;
using DreamBuilder.Core.Container;

namespace EOAULib
{
   public class Common
    {
       public static string NewGuid()
       {
           return Guid.NewGuid().ToString();
       }

       /// <summary>
       /// 声明接口
       /// </summary>
       IBusiness ibus = UContainer.Resolve<IBusiness>();


       /// <summary>
       /// 此为所有的导入都为新增
       /// </summary>
       /// <param name="Ori_Ds"></param>
       /// <param name="ImportTable"></param>
       /// <param name="Pkey"></param>
       /// <returns></returns>
       public DataSet ChangeDsForSave(DataSet Ori_Ds,string ImportTable,string Pkey)
       {
           try
           {
               DataSet ds = Ori_Ds.Copy();

               ds.Tables[ImportTable].Columns.Add("RowStatus", typeof(String)).DefaultValue = "1";
               ds.Tables[ImportTable].Columns.Add(ImportTable + "." + Pkey, typeof(String)).DefaultValue = "1";
               for (int i = 0; i < ds.Tables[ImportTable].Rows.Count; i++)
               {
                   ds.Tables[ImportTable].Rows[i][ImportTable + "." + Pkey] = NewGuid();
                   ds.Tables[ImportTable].Rows[i]["RowStatus"] = "1";
               }
               ds.Tables[ImportTable].AcceptChanges();
               ds.Tables[0].PrimaryKey = new DataColumn[]
               {
                   ds.Tables[0].Columns[ImportTable + "."+Pkey]
               };
               DreamBuilder.Core.Message.ResultInfo info = ibus.Save(ds);
               if (info.bSuccess==true)
               {
                   return ds;
               }
               else
               {
                   return null;
               }         
           }
           catch (Exception ex)
           {
               
               throw ex;
           }

           

          
 
       }



     
    }
}
